package farmer.gui;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.geom.RoundRectangle2D;

import core.gui.Button;
import farmer.game.MainGameState;

public class MainGameButton extends Button{

	public static final int Up = 0;
	public static final int Down = 1;
	public static final int Left = 2;
	public static final int Right = 3;
	public static final int ZoomIn = 4;
	public static final int ZoomOut = 5;
	
	
	private MainGameState state;
	private int type;
	
	public MainGameButton(String name, MainGameState state, int type) {
		super(name);
		this.state = state;
		this.type = type;
		boundingRect = new RoundRectangle2D.Float(0, 0, 10, 10, 10, 10);
		setSize(30, 30);
	}
	
	@Override
	public void isPressed(){
		switch(type){
		case(Up):
			state.buttonUp = true;
			break;
		case(Down):
			state.buttonDown = true;
			break;
		case(Left):
			state.buttonLeft = true;
			break;
		case(Right):
			state.buttonRight = true;
			break;
		case(ZoomIn):
			break;
		case(ZoomOut):
			break;
		}
	}
	
	@Override
	public void mouseReleased(MouseEvent e){
		super.mouseReleased(e);
		state.buttonUp = false;
		state.buttonDown = false;
		state.buttonLeft = false;
		state.buttonRight = false;
	}
	
	private BasicStroke stroke = new BasicStroke(1);
	private Font font = new Font("Button", Font.BOLD, 13);
	private Font zoomFont = new Font("Zoom", Font.PLAIN, 20);
	
	@Override
	protected void drawButton(Graphics2D g){
		if(type == ZoomIn || type == ZoomOut){
			g.setFont(zoomFont);
		}else{
			g.setFont(font);
		}
		int x = (int) boundingRect.getCenterX();
		int y = (int) boundingRect.getCenterY();
		int w = g.getFontMetrics().charsWidth(name.toCharArray(), 0, name.length());
		int h = g.getFontMetrics().getHeight();
		g.setColor(Color.black);
		g.setStroke(stroke);
		g.drawString(name, x-w/2, y+h/4);
	}
	
	Color darkGray = new Color(127, 127, 127);
	Color darkGray2 = new Color(140, 140, 140);
	Color background = new Color(1, 1, 1, 1f);
	private Color colorPressed = new Color(252, 158, 58);
	
	@Override
	protected void renderContains(Graphics2D g){
		g.setColor(background);
		g.fill(boundingRect);
		g.setStroke(new BasicStroke(3));
		g.setColor(darkGray);
		g.draw(boundingRect);
	}
	
	@Override
	protected void renderIsPressed(Graphics2D g){
		g.setColor(background);
		g.fill(boundingRect);
		g.setStroke(new BasicStroke(3));
		g.setColor(colorPressed);
		g.draw(boundingRect);
	}
	
	@Override
	protected void renderNormal(Graphics2D g){
		g.setColor(background);
		g.fill(boundingRect);
		g.setStroke(new BasicStroke(3));
		g.setColor(Color.black);
		g.draw(boundingRect);
	}
	
	

}
